package phoenix.web.page_objects;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.PageBaseWebExt;
import phoenix.core.config.extensions.ConfigExt;
import phoenix.core.data_models.PriceLinkDataModel;
import phoenix.core.data_models.PriceLinkDataModel.CreditsPrices;
import phoenix.core.data_models.UserProfileDataModel.PaymentDetails;
import phoenix.web.locators.base.PaymentPageLocatorsBase;

/**
 * Class provides access to web elements and actions on Payment page
 */
public class PaymentPage extends PageBaseWebExt
{

	/**
	 * Initializes the PaymentPage
	 */
	public PaymentPage(PhoenixManager p_manager)
	{
		super(p_manager);
	}

	/**
	 * Gets web elements by site
	 * @return PaymentPageLocatorsBase instance
	 */
	public PaymentPageLocatorsBase elements()
	{
		switch (manager.testModel().getSiteName())
		{
			case ConfigExt.SITE_ID_CLICKANDFLIRT:
			{
				return new phoenix.web.locators.clickandflirt.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_LOCALSGOWILD:
			{
				return new phoenix.web.locators.localsgowild.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_EBONYFLIRT:
			{
				return new phoenix.web.locators.ebonyflirt.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_CHEECKYLOVERS:
			{
				return new phoenix.web.locators.cheekylovers.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_WILDBUDDIES:
			{
				return new phoenix.web.locators.wildbuddies.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_FLIRT:
			{
				return new phoenix.web.locators.flirt.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_FOREIGNGIRLFRIEND:
			{
				return new phoenix.web.locators.foreigngirlfriend.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_BENAUGHTY:
			{
				return new phoenix.web.locators.benaughty.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_NAUGHTYFEVER:
			{
				return new phoenix.web.locators.naughtyfever.PaymentPageLocators();
			}
			case ConfigExt.SITE_ID_MATUREDATING:
			{
				return new phoenix.web.locators.maturedating.PaymentPageLocators();
			}
			default:
			{
				return null;
			}
		}
	}

	public void clickBackToSite()
	{
		log().info("Click link back to site");

		wd().waitForPresence(elements().linkBackToSite, "Link 'Back to site'");
		wd().click(elements().linkBackToSite);
	}

	public void clickChangePaymentDetails()
	{
		log().info("Click link change payment details");

		wd().waitForPresence(elements().linkChangePaymentDetails, "Link 'Change payment details'");
		wd().click(elements().linkChangePaymentDetails);
	}

	public void clickSubmitForm()
	{
		log().info("Click submit button");

		wd().waitForPresence(elements().btnSubmit, "Button 'Submit'");
		wd().click(elements().btnSubmit);
	}

	public void setCardNumber(PaymentDetails p_details)
	{
		log().info("Set card number");

		wd().waitForPresence(elements().txtCardNumber, "Field 'Card number'");
		wd().setElementText(elements().txtCardNumber, true, p_details.cardNumber);
	}

	public void setNameOnCard(PaymentDetails p_details)
	{
		log().info("Set name on card");

		wd().waitForPresence(elements().txtNameOnCard, "Field 'Name on card'");
		wd().setElementText(elements().txtNameOnCard, true, p_details.cardName);
	}

	public void setExpirationDateMonth(PaymentDetails p_details)
	{
		log().info("Set expiration date month");

		wd().waitForPresence(elements().selectExpirationDateMonth, "Select 'Expiration date month'");
		wd().selectByValue(elements().selectExpirationDateMonth, p_details.expireDateMonth);
	}

	public void setExpirationDateYear(PaymentDetails p_details)
	{
		log().info("Set expiration date year");

		wd().waitForPresence(elements().selectExpirationDateYear, "Select 'Expiration date year'");
		wd().selectByValue(elements().selectExpirationDateYear, p_details.expireDateYear);
	}

	public void setSecurityNumber(PaymentDetails p_details)
	{
		log().info("Set security number");

		wd().waitForPresence(elements().txtSecurityNumber, "Field 'Security number'");
		wd().setElementText(elements().txtSecurityNumber, true, p_details.securityNumber);
	}

	public void setFirstName(PaymentDetails p_details)
	{
		log().info("Set first name");

		wd().waitForPresence(elements().txtFirstName, "Field 'First name'");
		wd().setElementText(elements().txtFirstName, true, p_details.firstName);
	}

	public void setLastName(PaymentDetails p_details)
	{
		log().info("Set last name");

		wd().waitForPresence(elements().txtLastName, "Field 'Last name'");
		wd().setElementText(elements().txtLastName, true, p_details.lastName);
	}

	public void setBillingAddress(PaymentDetails p_details)
	{
		log().info("Set billing address");

		wd().waitForPresence(elements().txtBillingAddress, "Field 'Billing address'");
		wd().setElementText(elements().txtBillingAddress, true, p_details.billingAddress);
	}

	public void setCity(PaymentDetails p_details)
	{
		log().info("Set city");

		wd().waitForPresence(elements().txtCity, "Field 'City'");
		wd().setElementText(elements().txtCity, true, p_details.city);
	}

	public void setPostcode(PaymentDetails p_details)
	{
		log().info("Set postcode");

		wd().waitForPresence(elements().txtPostcode, "Field 'Postcode'");
		wd().setElementText(elements().txtPostcode, true, p_details.postcode);
	}

	public void setCountry(PaymentDetails p_details)
	{
		log().info("Set country");

		wd().waitForPresence(elements().selectCountry, "Select 'Country'");
		wd().setElementText(elements().selectCountry, true, p_details.country);
	}

	public boolean isMainBlockDisplayed()
	{
		return wd().isElementDisplayed(elements().txtCardNumber);
	}

	public boolean isExtendedBlockDisplayed()
	{
		return wd().isElementDisplayed(elements().txtFirstName);
	}

	public void setMainData(PaymentDetails p_details)
	{
		this.setCardNumber(p_details);
		this.setNameOnCard(p_details);
		this.setExpirationDateMonth(p_details);
		this.setExpirationDateYear(p_details);
		this.setSecurityNumber(p_details);
	}

	public void setExtendedData(PaymentDetails p_details)
	{
		this.setFirstName(p_details);
		this.setLastName(p_details);
		this.setBillingAddress(p_details);
		this.setCity(p_details);
		this.setPostcode(p_details);
	}

	public void click3DayPackage()
	{
		log().info("Click 3 day package");

		wd().waitForPresence(elements().block3DayPackage, "Block '3 day package'");
		wd().click(elements().block3DayPackage);
	}

	public void click1MonthPackage()
	{
		log().info("Click 1 month package");

		wd().waitForPresence(elements().block1MonthPackage, "Block '1 month package'");
		wd().click(elements().block1MonthPackage);
	}

	public void click3MonthPackage()
	{
		log().info("Click 3 month package");

		wd().waitForPresence(elements().block3MonthPackage, "Block '3 month package'");
		wd().click(elements().block3MonthPackage);
	}

	public void click6MonthPackage()
	{
		log().info("Click 6 month package");

		wd().waitForPresence(elements().block6MonthPackage, "Block '6 month package'");
		wd().click(elements().block6MonthPackage);
	}

	public void selectPaymentPackage()
	{
		log().info("Select random package");

		int p_number = manager.randomizer().getRandomInt(1, 4);

		switch (p_number)
		{
			case 1:
			{
				this.click3DayPackage();
				break;
			}
			case 2:
			{
				this.click1MonthPackage();
				break;
			}
			case 3:
			{
				this.click3MonthPackage();
				break;
			}
			case 4:
			{
				this.click6MonthPackage();
				break;
			}
		}

		manager.testUser().setMembershipStatus(1);
	}

	public void clickCredits20()
	{
		log().info("Click 20 credits");

		wd().waitForPresence(elements().blockCredits20, "Block '20 credits'");
		wd().click(elements().blockCredits20);
	}

	public void clickCredits40()
	{
		log().info("Click 40 credits");

		wd().waitForPresence(elements().blockCredits40, "Block '40 credits'");
		wd().click(elements().blockCredits40);
	}

	public void clickCredits80()
	{
		log().info("Click 80 credits");

		wd().waitForPresence(elements().blockCredits80, "Block '80 credits'");
		wd().click(elements().blockCredits80);
	}

	public void clickCredits160()
	{
		log().info("Click 160 credits");

		wd().waitForPresence(elements().blockCredits160, "Block '160 credits'");
		wd().click(elements().blockCredits160);
	}

	public void clickCredits320()
	{
		log().info("Click 320 credits");

		wd().waitForPresence(elements().blockCredits320, "Block '320 credits'");
		wd().click(elements().blockCredits320);
	}

	public void clickCredits500()
	{
		log().info("Click 500 credits");

		wd().waitForPresence(elements().blockCredits500, "Block '500 credits'");
		wd().click(elements().blockCredits500);
	}

	public void clickCredits1000()
	{
		log().info("Click 1000 credits");

		wd().waitForPresence(elements().blockCredits1000, "Block '1000 credits'");
		wd().click(elements().blockCredits1000);
	}

	public void selectPaymentCredits()
	{
		log().info("Select random credits");

		int p_number = manager.randomizer().getRandomInt(1, 7);

		switch (p_number)
		{
			case 1:
			{
				this.clickCredits20();
				manager.testUser().setCredits("20");
				break;
			}
			case 2:
			{
				this.clickCredits40();
				manager.testUser().setCredits("40");
				break;
			}
			case 3:
			{
				this.clickCredits80();
				manager.testUser().setCredits("80");
				break;
			}
			case 4:
			{
				this.clickCredits160();
				manager.testUser().setCredits("160");
				break;
			}
			case 5:
			{
				this.clickCredits320();
				manager.testUser().setCredits("320");
				break;
			}
			case 6:
			{
				this.clickCredits500();
				manager.testUser().setCredits("500");
				break;
			}
			case 7:
			{
				this.clickCredits1000();
				manager.testUser().setCredits("1000");
				break;
			}
		}

		manager.testUser().setMembershipStatus(1);
	}

	public void clickFullUpgrade()
	{
		log().info("Click full upgrade feature");

		wd().waitForPresence(elements().blockFullUpgrade, "Block 'Full upgrade feature'");
		wd().click(elements().blockFullUpgrade);
	}

	public void clickSearchUpgrade()
	{
		log().info("Click search upgrade feature");

		wd().waitForPresence(elements().blockSearchUpgrade, "Block 'Search upgrade feature'");
		wd().click(elements().blockSearchUpgrade);
	}

	public void clickCommunicationUpgrade()
	{
		log().info("Click communication upgrade feature");

		wd().waitForPresence(elements().blockCommunicationUpgrade, "Block 'Search communication feature'");
		wd().click(elements().blockCommunicationUpgrade);
	}

	public int selectPaymentFeatures()
	{
		log().info("Select random features");

		int p_number = manager.randomizer().getRandomInt(1, 3);
		int p_permissoin = 0;

		switch (p_number)
		{
			case 1:
			{
				this.clickFullUpgrade();
				manager.testUser().setMembershipStatus(4);
				p_permissoin = 4;
				break;
			}
			case 2:
			{
				this.clickSearchUpgrade();
				manager.testUser().setMembershipStatus(3);
				p_permissoin = 3;
				break;
			}
			case 3:
			{
				this.clickCommunicationUpgrade();
				manager.testUser().setMembershipStatus(2);
				p_permissoin = 2;
				break;
			}
		}

		return p_permissoin;
	}

	public void waitForPageLoad()
	{
		wd().waitForVisibility(elements().blockPaymentSubscription, "Block 'Payment page'");
	}

	public void waitForFeaturesPagePresence()
	{
		wd().waitForPresence(elements().blockAdditionalFeatures, "Block 'Features page'");
	}

	public boolean isPaymentSuccessfulPopupDisplayed()
	{
		wd().waitForPresence(elements().blockPaymentSuccessPopUp, "Block 'Payment successful popup'");

		return wd().isElementDisplayed(elements().blockPaymentSuccessPopUp);
	}

	public void clickCloseSuccessfulPopup()
	{
		log().info("Click close successful popup");

		wd().waitForPresence(elements().blockPaymentSuccessPupUpClose, "Button 'Close payment successful popup'");
		wd().click(elements().blockPaymentSuccessPupUpClose);
	}

	public void waitForFailedPagePresence()
	{
		wd().waitForPresence(elements().blockPaymentFailedHeder, "Block 'Payment failed page'");
	}

	public void waitForSuccessfulPagePresence()
	{
		wd().waitForPresence(elements().btnGoToSite, "Button 'Go to site");
	}

	public void clickGoToSite()
	{
		log().info("Click button go to site");

		wd().waitForPresence(elements().btnGoToSite, "Button 'Go to site");
		wd().click(elements().btnGoToSite);
	}

	public void clickContinue()
	{
		log().info("Click continue");

		wd().waitForPresence(elements().btnContinue, "Button 'Continue'");
		wd().click(elements().btnContinue);
	}

	/**
	 * TODO need refactoring
	 */
	public void typeCardNumber(String p_cardNumber)
	{
		log().info("Type value in card number field...");

		if (wd().isElementDisplayed(elements().linkChangePaymentDetails) && !wd().isElementDisplayed(elements().txtCardNumber))
		{
			wd().click(elements().linkChangePaymentDetails);
			wd().wait(3);
		}

		wd().waitForPresence(elements().txtCardNumber, "Field 'Card number' doesn't appear");
		wd().typeAndClear(elements().txtCardNumber, p_cardNumber);
	}

	/**
	 * TODO need refactoring
	 */
	public void clickOnFieldCardNumber()
	{
		log().info("Click on card number field...");

		if (wd().isElementDisplayed(elements().linkChangePaymentDetails) && !wd().isElementDisplayed(elements().txtCardNumber))
		{
			wd().click(elements().linkChangePaymentDetails);
			wd().wait(3);
		}

		wd().waitForPresence(elements().txtCardNumber, "Field 'Card number' doesn't appear");
		wd().click(elements().txtCardNumber);
		wd().wait(2);

	}

	/**
	 * TODO need refactoring
	 */
	public void clickOnFieldCardName()
	{
		log().info("Click on card name field...");

		if (wd().isElementDisplayed(elements().linkChangePaymentDetails) && !wd().isElementDisplayed(elements().txtNameOnCard))
		{
			wd().click(elements().linkChangePaymentDetails);
			wd().wait(3);
		}

		wd().waitForPresence(elements().txtNameOnCard, "Field 'Card name' doesn't appear");
		wd().click(elements().txtNameOnCard);
		wd().wait(2);

	}

	/**
	 * TODO need refactoring
	 */
	public boolean isValidatedField(String field_name)
	{
		log().info("Check is field " + field_name + " validate...");

		wd().wait(4);

		switch (field_name)
		{
			case "card_number":
			{
				if (wd().getWebElements(elements().blockValidatioList).get(0).getAttribute("class").contains("error")
						&& wd().getWebElements(elements().blockValidatioList).get(0).findElement(elements().blockValidationError).isDisplayed())
				{
					log().info("Check is field " + field_name + " not validated!");
					return false;
				}
				else
				{
					log().info("Check is field " + field_name + " is validated");
					return true;
				}
			}
			case "card_name":
			{
				if (wd().getWebElements(elements().blockValidatioList).get(1).getAttribute("class").contains("error")
						&& wd().getWebElements(elements().blockValidatioList).get(1).findElement(elements().blockValidationError).isDisplayed())
				{
					log().info("Check is field " + field_name + " not validated!");
					return false;
				}
				else
				{
					log().info("Check is field " + field_name + " is validated");
					return true;
				}
			}
			case "card_date":
			{
				if (wd().getWebElements(elements().blockValidatioList).get(2).getAttribute("class").contains("error")
						&& wd().getWebElements(elements().blockValidatioList).get(2).findElement(elements().blockValidationError).isDisplayed())
				{
					log().info("Check is field " + field_name + " not validated!");
					return false;
				}
				else
				{
					log().info("Check is field " + field_name + " is validated");
					return true;
				}
			}
			case "card_code":
			{
				if (wd().getWebElements(elements().blockValidatioList).get(3).getAttribute("class").contains("error")
						&& wd().getWebElements(elements().blockValidatioList).get(3).findElement(elements().blockValidationError).isDisplayed())
				{
					log().info("Check is field " + field_name + " not validated!");
					return false;
				}
				else
				{
					log().info("Check is field " + field_name + " is validated");
					return true;
				}
			}
			default:
			{
				testExeption("Unknown Card filed name!");
				return false;
			}
		}
	}

	/**
	 * TODO need refactoring
	 */
	public void typeCardName(String p_cardNameValue)
	{
		log().info("Type value in card name field...");

		if (wd().isElementDisplayed(elements().linkChangePaymentDetails) && !wd().isElementDisplayed(elements().txtNameOnCard))
		{
			wd().wait(3);
		}

		wd().waitForPresence(elements().txtNameOnCard, "Field 'Card number' doesn't appear");
		wd().typeAndClear(elements().txtNameOnCard, p_cardNameValue);

	}

	/**
	 * TODO need refactoring
	 */
	public void clickOnFieldSecurityCode()
	{
		log().info("Click on card Security Code field...");

		if (wd().isElementDisplayed(elements().linkChangePaymentDetails) && !wd().isElementDisplayed(elements().txtSecurityNumber))
		{
			wd().click(elements().linkChangePaymentDetails);
			wd().wait(3);
		}

		wd().waitForPresence(elements().txtSecurityNumber, "Field 'Security number' doesn't appear");
		wd().click(elements().txtSecurityNumber);
		wd().wait(2);

	}

	/**
	 * TODO need refactoring
	 */
	public void typeCardSecurityCode(String p_cardSecurityCodeValue)
	{
		log().info("Type value in card number field...");

		if (wd().isElementDisplayed(elements().linkChangePaymentDetails) && !wd().isElementDisplayed(elements().txtSecurityNumber))
		{
			wd().click(elements().linkChangePaymentDetails);
			wd().wait(3);
		}

		wd().waitForPresence(elements().txtSecurityNumber, "Field 'Card number' doesn't appear");
		wd().typeAndClear(elements().txtSecurityNumber, p_cardSecurityCodeValue);
	}

	/**
	 * TODO need refactoring
	 */
	public void selectExpiryDate(String p_mounth, String p_year)
	{
		log().info("Click on card Expity date fields...");

		if (wd().isElementDisplayed(elements().linkChangePaymentDetails) && !wd().isElementDisplayed(elements().selectExpirationDateMonth))
		{
			wd().click(elements().linkChangePaymentDetails);
			wd().wait(3);
		}

		// Select expiration date Month
		wd().selectByValue(elements().selectExpirationDateMonth, p_mounth);
		// Select expiration date Year
		wd().selectByValue(elements().selectExpirationDateYear, p_year);
	}

	/**
	 * TODO need refactoring
	 */
	public void getPackagePrices(PriceLinkDataModel prices)
	{
		if (manager.isFlirt() || manager.isWB() || manager.isLGW())
		{
			getPackagePrices_FLIRT_WB_LGW(prices);
		}
		else if (manager.isBN() || manager.isCNF())
		{
			getPackagePrices_BN_CNF(prices);
		}
	}

	/**
	 * TODO need refactoring
	 */
	private void getPackagePrices_BN_CNF(PriceLinkDataModel prices)
	{
		String price_3D = wd().getWebElement(elements().block3DayPackage).findElement(elements().blockAmount).getText()
				+ "." + wd().getWebElement(elements().block3DayPackage).findElement(elements().blockCent).getText();

		log().info("Price of 3day package: " + price_3D);

		String price_1M = wd().getWebElement(elements().block1MonthPackage).findElement(elements().blockAmount).getText()
				+ "." + wd().getWebElement(elements().block1MonthPackage).findElement(elements().blockCent).getText();

		log().info("Price of 1M package: " + price_1M);

		String price_3M = wd().getWebElement(elements().block3MonthPackage).findElement(elements().blockAmount).getText()
				+ "." + wd().getWebElement(elements().block3MonthPackage).findElement(elements().blockCent).getText();

		log().info("Price of 3M package: " + price_3M);

		String price_6M = wd().getWebElement(elements().block6MonthPackage).findElement(elements().blockAmount).getText()
				+ "." + wd().getWebElement(elements().block6MonthPackage).findElement(elements().blockCent).getText();

		log().info("Price of 6M package: " + price_6M);

		prices.setActual3dPrice(price_3D).setActual1mPrice(price_1M).setActual3mPrice(price_3M).setActual6mPrice(price_6M);
	}

	/**
	 * TODO need refactoring
	 */
	private void getPackagePrices_FLIRT_WB_LGW(PriceLinkDataModel prices)
	{
		String price_3D = wd().getWebElement(elements().block3DayPackage).findElement(elements().blockPrice).getText();
		price_3D = manager.stringHelperExt().getPriceFromString(price_3D);

		log().info("Price of 3day package: " + price_3D);

		String price_1M = wd().getWebElement(elements().block1MonthPackage).findElement(elements().blockPrice).getText();
		price_1M = manager.stringHelperExt().getPriceFromString(price_1M);

		log().info("Price of 1M package: " + price_1M);

		String price_3M = wd().getWebElement(elements().block3MonthPackage).findElement(elements().blockPrice).getText();
		price_3M = manager.stringHelperExt().getPriceFromString(price_3M);

		log().info("Price of 3M package: " + price_3M);

		String price_6M = wd().getWebElement(elements().block6MonthPackage).findElement(elements().blockPrice).getText();
		price_6M = manager.stringHelperExt().getPriceFromString(price_6M);

		log().info("Price of 6M package: " + price_6M);

		prices.setActual3dPrice(price_3D).setActual1mPrice(price_1M).setActual3mPrice(price_3M).setActual6mPrice(price_6M);
	}

	/**
	 * TODO need refactoring
	 */
	public void getFeaturesPrices(PriceLinkDataModel p_price)
	{
		String price_vip = wd().getWebElement(elements().blockSearchUpgrade).findElement(elements().blockAmount).getText()
				+ "." + wd().getWebElement(elements().blockSearchUpgrade).findElement(elements().blockCent).getText();

		log().info("Price of vip package: " + price_vip);

		String price_free_communicate = wd().getWebElement(elements().blockCommunicationUpgrade).findElement(elements().blockAmount).getText()
				+ "." + wd().getWebElement(elements().blockCommunicationUpgrade).findElement(elements().blockCent).getText();

		log().info("Price of free_communicate package: " + price_free_communicate);

		String price_full_upgrade = wd().getWebElement(elements().blockFullUpgrade).findElement(elements().blockAmount).getText()
				+ "." + wd().getWebElement(elements().blockFullUpgrade).findElement(elements().blockCent).getText();

		log().info("Price of full_upgrade package: " + price_full_upgrade);

		p_price.setActualFreeCommunicatePrice(price_free_communicate).setActualVipPrice(price_vip).setActualFullUpgradePrice(price_full_upgrade);

	}

	/**
	 * TODO need refactoring
	 */
	public void clickPay()
	{
		wd().click(elements().bntPay);
	}

	/**
	 * TODO need refactoring
	 */
	public void getCredits(CreditsPrices prices)
	{
		wd().waitForPresence(elements().blockCredits20, "20 Credits block not appear");
		wd().click(elements().blockCredits20);
		wd().wait(1);

		String price_20 = manager.stringHelperExt().getPriceFromString((wd().getText(elements().blockPrice)));
		log().info("Price of price_20 package: " + price_20);

		wd().waitForPresence(elements().blockCredits40, "40 Credits block not appear");
		wd().click(elements().blockCredits40);
		wd().wait(1);

		String price_40 = manager.stringHelperExt().getPriceFromString((wd().getText(elements().blockPrice)));
		log().info("Price of price_40 package: " + price_40);

		wd().waitForPresence(elements().blockCredits80, "80 Credits block not appear");
		wd().click(elements().blockCredits80);
		wd().wait(1);

		String price_80 = manager.stringHelperExt().getPriceFromString((wd().getText(elements().blockPrice)));
		log().info("Price of price_80 package: " + price_80);

		wd().waitForPresence(elements().blockCredits160, "160 Credits block not appear");
		wd().click(elements().blockCredits160);
		wd().wait(1);

		String price_160 = manager.stringHelperExt().getPriceFromString((wd().getText(elements().blockPrice)));
		log().info("Price of price_160 package: " + price_160);

		wd().waitForPresence(elements().blockCredits320, "320 Credits block not appear");
		wd().click(elements().blockCredits320);
		wd().wait(1);

		String price_320 = manager.stringHelperExt().getPriceFromString((wd().getText(elements().blockPrice)));
		wd().waitForPresence(elements().blockCredits320, "500 Credits block not appear");
		wd().click(elements().blockCredits500);
		wd().wait(1);

		String price_500 = manager.stringHelperExt().getPriceFromString((wd().getText(elements().blockPrice)));
		log().info("Price of price_500 package: " + price_500);

		wd().waitForPresence(elements().blockCredits1000, "1000 Credits block not appear");
		wd().click(elements().blockCredits1000);
		wd().wait(1);

		String price_1000 = manager.stringHelperExt().getPriceFromString((wd().getText(elements().blockPrice)));
		log().info("Price of price_1000 package: " + price_1000);

		prices.setActual20(price_20).setActual40(price_40).setActual80(price_80).setActual160(price_160).setActual320(price_320).setActual500(price_500)
				.setActual1000(price_1000);
	}

	public boolean isPaymentPage()
	{
		log().info("Check current page is it the Payment page");

		wd().waitForPresence(manager.web().paymentPage().elements().blockPaymentDetails, "Block 'Payment details' doesn't appear");

		if (manager.testUser().getMembershipStatus() != 0)
		{
			return wd().isUrlContains("/pay/features", true);
		}
		else
		{
			return wd().isUrlContains("/pay/membership", true);
		}
	}

	public boolean isPaymentAuthorizationPresent()
	{
		return wd().isElementDisplayed(elements().txtCardNumberAuthorization);
	}

	public void setCardNumberAuthorization(PaymentDetails p_details)
	{
		log().info("Set card number authorization");

		wd().waitForPresence(elements().txtCardNumberAuthorization, "Field 'Card number authorization'");
		wd().setElementText(elements().txtCardNumberAuthorization, true, p_details.cardNumber);
	}

	public void setNameOnCardAuthorization(PaymentDetails p_details)
	{
		log().info("Set name on card authorization");

		wd().waitForPresence(elements().txtNameOnCardAuthorization, "Field 'Name on card authorization'");
		wd().setElementText(elements().txtNameOnCardAuthorization, true, p_details.cardName);
	}

	public void setExpirationDateMonthAuthorization(PaymentDetails p_details)
	{
		log().info("Set expiration date month authorization");

		wd().waitForPresence(elements().selectExpirationDateMonthAuthorization, "Select 'Expiration date month authorization'");
		wd().selectByValue(elements().selectExpirationDateMonthAuthorization, p_details.expireDateMonth);
	}

	public void setExpirationDateYearAuthorization(PaymentDetails p_details)
	{
		log().info("Set expiration date year authorization");

		wd().waitForPresence(elements().selectExpirationDateYearAuthorization, "Select 'Expiration date year authorization'");
		wd().selectByValue(elements().selectExpirationDateYearAuthorization, p_details.expireDateYear);
	}

	public void setSecurityNumberAuthorization(PaymentDetails p_details)
	{
		log().info("Set security number authorization");

		wd().waitForPresence(elements().txtSecurityNumberAuthorization, "Field 'Security number authorization'");
		wd().setElementText(elements().txtSecurityNumberAuthorization, true, p_details.securityNumber);
	}

	public void clickSubmitAuthorization()
	{
		log().info("Click submit authorization");

		wd().waitForPresence(elements().btnSubmitAuthorization, " Button 'Submit authorization'");
		wd().click(elements().btnSubmitAuthorization);
	}

	public void setPaymentAuthorizationData(PaymentDetails p_details)
	{
		this.setCardNumberAuthorization(p_details);
		this.setNameOnCardAuthorization(p_details);
		this.setExpirationDateMonthAuthorization(p_details);
		this.setExpirationDateYearAuthorization(p_details);
		this.setSecurityNumberAuthorization(p_details);
	}

	public void waitForSuccessAuthorizationPopup()
	{
		wd().waitForVisibility(elements().blockSuccessAuthorizationPopup, "Block 'Success authorization popup'");
	}

	public void clickContinueAuthorizationPopup()
	{
		wd().waitForPresence(elements().bntContinueAuthorizationPopup, "Button 'Continue authorization popup'");
		wd().click(elements().bntContinueAuthorizationPopup);
	}
}
